package com.ruihu.admin.config;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.pagination.optimize.JsqlParserCountOptimize;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @author zhuoda
 */
@EnableTransactionManagement
@Configuration
@MapperScan({"com.ruihu.admin.module.**.dao"})
public class MybatisPlusConfig {

    /**
     * SQL排序插件
     * @return
     */
    @Bean
    @Order(1)
    public OrderByInterceptor mybatisPlusInterceptor() {
        return new OrderByInterceptor();
    }

    /**
     * 分页插件
     */
    @Bean
    @Order(2)
    public PaginationInterceptor paginationInterceptor() {
        // 开启 count 的 join 优化,只针对 left join !!!
        return new PaginationInterceptor().setCountSqlParser(new JsqlParserCountOptimize(true));
    }

}
